package org.zoomdev.zoom.dao.impl;

import org.zoomdev.zoom.aop.Getter;
import org.zoomdev.zoom.aop.Setter;
import org.zoomdev.zoom.aop.factory.GetterFactory;
import org.zoomdev.zoom.aop.factory.SetterFactory;

import java.lang.reflect.Field;
import java.lang.reflect.Type;

final class BeanEntityField extends AbstractEntityField {

    private final Field field;

    private final Setter setter;

    private final Getter getter;

    BeanEntityField(Field field) {
        super();
        this.field = field;
        this.setter = SetterFactory.FACTORY.create(field);
        this.getter = GetterFactory.FACTORY.create(field);
    }

    @Override
    public Object get(Object target) {
        return getter.get(target);
    }

    @Override
    public void set(Object data, Object fieldValue) {
        setter.set(data, fieldValue);
    }

    @Override
    public String getFieldName() {
        return field.getName();
    }

    @Override
    public Type getFieldType() {
        return field.getGenericType();
    }


}
